import 'package:url_launcher/url_launcher.dart';
import '../../public.dart';

class HomeCarousel extends StatelessWidget {
  final List<CarouselChartEntity> list;
  const HomeCarousel({super.key, required this.list});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16),
      child: CarouselWidget(
        height: 240,
        borderRadius: BorderRadius.circular(12),
        imageUrls: list
            .map((e) => CryptoUtil.decryptData(e.chartUrl) ?? '')
            .toList(),
        onTap: (index) {
          final selectedImg = list[index];
          if (selectedImg.redirectUrl != null) {
            try {
              launchUrl(Uri.parse(selectedImg.redirectUrl!));
            } catch (e) {
              throw Exception('Failed to launch URL: $e');
            }
          }
        },
      ),
    );
  }
}
